package org.handyc.game.panel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.AffineTransform;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import org.handyc.game.frame.GameFrame;
import org.handyc.game.frame.TestFrame;
import org.handyc.game.graphics.Tank;
import org.handyc.game.object.GameObject;
import org.handyc.game.resource.GameResource;

public class TestPanel extends JPanel {

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					GameFrame frame = new GameFrame();
					frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					frame.setBounds(100, 100, 800, 600);
					final TestPanel panel = new TestPanel();
					panel.setBorder(new EmptyBorder(5, 5, 5, 5));
					panel.setLayout(new BorderLayout(0, 0));
					frame.setContentPane(panel);
					frame.addKeyListener(new org.handyc.game.event.KeyListener() {
						public void onTrigger() {

							human.moveXy(0, -10);

						}
					}, KeyEvent.VK_UP);
					frame.addKeyListener(new org.handyc.game.event.KeyListener() {
						public void onTrigger() {

							human.moveXy(0, 10);

						}
					}, KeyEvent.VK_DOWN);
					frame.addKeyListener(new org.handyc.game.event.KeyListener() {
						public void onTrigger() {
							human.moveXy(-10, 0);
						}
					}, KeyEvent.VK_LEFT);
					frame.addKeyListener(new org.handyc.game.event.KeyListener() {
						public void onTrigger() {
							human.moveXy(10, 0);

						}
					}, KeyEvent.VK_RIGHT);

					frame.addKeyListener(new org.handyc.game.event.KeyListener() {
						public void onTrigger() {
							human.moveXy(-7, -7);

						}
					}, KeyEvent.VK_UP, KeyEvent.VK_LEFT);
					frame.addKeyListener(new org.handyc.game.event.KeyListener() {
						public void onTrigger() {
							human.moveXy(7, -7);

						}
					}, KeyEvent.VK_UP, KeyEvent.VK_RIGHT);
					frame.addKeyListener(new org.handyc.game.event.KeyListener() {
						public void onTrigger() {
							human.moveXy(-7, 7);

						}
					}, KeyEvent.VK_DOWN, KeyEvent.VK_LEFT);
					frame.addKeyListener(new org.handyc.game.event.KeyListener() {
						public void onTrigger() {
							human.moveXy(7, 7);

						}
					}, KeyEvent.VK_DOWN, KeyEvent.VK_RIGHT);

					frame.addKeyListener(new org.handyc.game.event.KeyListener() {
						public void onTrigger() {
							human.rotate(30);

						}
					}, KeyEvent.VK_X);
					frame.addKeyListener(new org.handyc.game.event.KeyListener() {
						public void onTrigger() {
							human.rotate(-30);

						}
					}, KeyEvent.VK_Z);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the panel.
	 */
	public TestPanel() {
		Thread t = new Thread(new Runnable() {

			public void run() {
				while (true) {
					try {
						Thread.sleep(30);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					repaint();
				}

			}
		});
		t.start();

	}

	public static int x = 100;
	public static int y = 100;

	// public static GameObject human = new
	// GameObject(GameResource.getImageIcon("human01.png"), 100, 100, 64, 64);

	public static GameObject human = new GameObject(GameResource.getImageIcon("human01.png"), 300, 300, 64, 64, 32, 32);

	@Override
	public void paint(Graphics g) {
		super.paint(g);
		Graphics2D g2d = (Graphics2D) g;
		g2d.drawImage(human.getIcon().getImage(), human.getAffineTransform(), human.getIcon().getImageObserver());

	}

}
